import request from '@/config/axios'

export enum CatalogStatus {
  'ENABLE' = 1,
  'DISABLE' = 2
}

export type CatalogVO = {
  id: string | 0
  parentId: string
  catalogName: string
  catalogDesc: string
  catalogStatus: number
  sortNo: number
}

export type CatalogTree = CatalogVO & {
  children: CatalogVO[]
}

export type CatalogDTO = Partial<CatalogVO>

export type CatalogCreateDTO = Omit<CatalogVO, 'id'>

const baseURL = '/train/course/catalog'

/** 根据课程id获取目录列表 */
export const getListByCourseId = (courseId: string) =>
  request.get<CatalogVO[]>({
    url: `${baseURL}/list-by-course-id`,
    params: { courseId }
  })

/** 根据目录id获取目录详情 */
export const get = (id: string) =>
  request.get<CatalogVO>({
    url: `${baseURL}/get-course-catalog-detail`,
    params: { id }
  })

/** 新增 */
export const create = (data: CatalogCreateDTO) =>
  request.post<boolean>({
    url: `${baseURL}/create`,
    data
  })

/** 更新 */
export const update = (data: CatalogDTO) =>
  request.post<boolean>({
    url: `${baseURL}/update`,
    data
  })

/** 删除 */
export const deleteById = (id: string) =>
  request.post<boolean>({
    url: `${baseURL}/delete`,
    params: { id }
  })
